package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by shixi  on 2019/6/24
 */
@Slf4j
public class Solution617 {

    public static void main(String[] args) {
        Solution617 solution = new Solution617();

        TreeNode root = new TreeNode(1);

        TreeNode left = new TreeNode(3);
        TreeNode right = new TreeNode(2);
        TreeNode node_5 = new TreeNode(5);

        root.left = left;
        root.right = right;
        left.left = node_5;

        TreeNode root2 = new TreeNode(2);

        TreeNode left2 = new TreeNode(1);
        TreeNode right2 = new TreeNode(3);
        TreeNode node_4 = new TreeNode(4);
        TreeNode node_7 = new TreeNode(7);

        root2.left = left2;
        root2.right = right2;
        left2.right = node_4;
        right2.right = node_7;

        TreeNode result = solution.mergeTrees(root, root2);
        log.info("{}", result);

    }
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        if (root1 == null) {
            return root2;
        }
        if (root2 == null) {
            return root1;
        }
        TreeNode merged = new TreeNode(root1.val + root2.val);
        merged.left = mergeTrees(root1.left, root2.left);
        merged.right = mergeTrees(root1.right, root2.right);
        return merged;
    }

}

